home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_1
/
usum
< prev
next >
Wrap
Text File
|
1995-03-31
|
3KB
|
108 lines
The built in unit system of the HP48 has one disadvantage, the fact that, say,
0.75_h 2 * is given as 1.5_h rather than 1_h+30_min. This program performs such
conversions
The basic program is \->USUM which looks at the list of lists UNIT.L. UNIT.L's
sublists each consist of unit objects each with coefficient 1 arranged in
decreasing order of size (look at the example I have given to get the format).
All the units in a sublist must have the same dimensions. The program can only
(obviously) work with units contained in UNIT.L. If you try to use another
unit, it will report an error ("Unit Not Found")
The program UCONV is similar to \->USUM, but instead of taking it's list of
units by search UNIT.L for an appropriate sublist, it takes a simple list of
units in Top of stack and performs the conversion on the unit object 2nd on
stack. The List must be arranged in decreasing order of size as above.
The program USEARCH searches the UNIT.L variable for the sublist that contains
the unit in top of stack and returns the original unit in 2nd on stack and the
appropriate list in Top of Stack (thus the stack is left in the correct form
for UCONV).
The demonstration UNIT.L variable contains the following Units :
1_mi 1_chain 1_rd 1_yd 1_ft 1_in (1st sublist - length)
1_mi 2 1_acre 1_yd 2 1_ft 2 1_in 2 (2nd sublist - area)
1_bbl 1_bu 1_pk 1_galUK 1_qt 1_pt 1_cu 1_tbsp 1_tsp (3rd sublist - volume)
1_yr 1_d 1_h 1_min 1_s (4th sublist - time)
1_tonUK 1_lb 1_oz (5th sublist - mass)
Note that due to the fact that many of the old units had several definitions,
and the fact that 1_yr <> 365_d, the answer may not be what you expect. It may
be useful to define some units of your own to get round this problem
-tony Duell
Janet: ARD@UK.AC.BRIS.SIVA
Bitnet: ARD@SIVA.BRIS.AC.UK
------------------>8---------------------->8--------------------->8----------
%%HP: T(3)A(R)F(.);
DIR
\->USUM
\<< USEARCH UCONV
\>>
UNIT.L $ $ '1_mi'
'1_chain' '1_rd' '1
_yd' '1_ft' '1_in'
$ '1_mi 2' '1_
acre' '1_yd 2' '1_
ft 2' '1_in 2' $
'1_bbl' '1_bu' '1_
pk' '1_galUK' '1_qt
' '1_pt' '1_cu' '1_
tbsp' '1_tsp' $ '
1_yr' '1_d' '1_h' '
1_min' '1_s' $ '1
_tonUK' '1_lb' '1_
oz'
UA
\<< DUP SIZE 1 -
2 SWAP SUB + "+" +
\>>
UCONV
\<< DUP SIZE \-> u
ul sz
\<< "" 1 sz 1 -
FOR n u ul
n GET CONVERT
IF DUP
UVAL IP 0 \=/
THEN OBJ\->
OVER FP OVER \->UNIT
'u' STO SWAP IP
SWAP \->UNIT \->STR UA
ELSE DROP
END
NEXT u ul
sz GET CONVERT DUP
UVAL
IF 0 \=/
THEN \->STR
UA
ELSE DROP
END DUP
SIZE 1 - 1 SWAP SUB
"'" + "'" SWAP +
OBJ\->
\>>
\>>
USEARCH
\<< 0 \-> n
\<<
DO 'n' INCR
IF UNIT.L
SIZE >
THEN
"Unit not found"
DOERR
END
UNIT.L n GET OVER
OBJ\-> SWAP DROP POS
UNTIL 0 >
END UNIT.L
n GET
\>>
\>>
END